package o;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build.VERSION;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.ConsoleMessage;
import android.webkit.SslErrorHandler;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.huawei.appgallery.agreementimpl.view.activity.HwHiAppPrivacyJs;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import o.axa.f;
import o.axa.h;
import o.bjx.d;

public class ayq {
    public static final int ॱॱ = d.ˊ;
    protected boolean ʻ = true;
    private int ʻॱ;
    protected boolean ʼ = false;
    protected TextView ʽ = null;
    protected ActionBar ˊ;
    public String ˊॱ;
    protected WebView ˋ;
    protected int ˋॱ = 1;
    protected LinearLayout ˎ;
    protected ImageView ˏ;
    protected Handler ˏॱ = new Handler();
    protected boolean ͺ = false;
    protected ProgressBar ॱ;
    protected String ॱˊ;
    protected b ॱˋ = new b(this);
    private boolean ॱˎ = false;
    protected Context ᐝ;
    protected boolean ᐝॱ = false;

    protected class b {
        final /* synthetic */ ayq ˊ;

        protected b(ayq o_ayq) {
            this.ˊ = o_ayq;
        }

        private void ˊ() {
            Log.d("WebViewDelegate", "initTitle");
            try {
                this.ˊ.ˊ.setHomeButtonEnabled(false);
                this.ˊ.ˊ.setDisplayHomeAsUpEnabled(false);
                this.ˊ.ˊ.setDisplayShowCustomEnabled(true);
                this.ˊ.ˊ.setDisplayOptions(16);
                this.ˊ.ˊ.setCustomView(f.ʼॱ);
                View customView = this.ˊ.ˊ.getCustomView();
                azb.ˏ(customView);
                this.ˊ.ˏ = (ImageView) customView.findViewById(o.axa.b.ͺॱ);
                this.ˊ.ʽ = (TextView) customView.findViewById(o.axa.b.ˊ);
                if (azc.ˎ().ॱ() < 17) {
                    this.ˊ.ˊ.setBackgroundDrawable(this.ˊ.ᐝ.getResources().getDrawable(axa.d.ˊ));
                }
                this.ˊ.ˏ.setOnClickListener(new OnClickListener(this) {
                    final /* synthetic */ b ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void onClick(View view) {
                        this.ॱ.ˊ.ʽ();
                    }
                });
            } catch (Exception e) {
                Log.e("WebViewDelegate", "initTitle error: " + e);
            }
        }

        public void ˋ(String str) {
            if (!"*#title*#".equals(str) && this.ˊ.ʽ != null) {
                this.ˊ.ʽ.setText(str);
            }
        }
    }

    public class c extends WebChromeClient {
        final /* synthetic */ ayq ˏ;

        public c(ayq o_ayq) {
            this.ˏ = o_ayq;
        }

        public void onProgressChanged(WebView webView, int i) {
            if (!this.ˏ.ˋ() && this.ˏ.ॱ != null) {
                if (i == 100) {
                    this.ˏ.ॱ.setVisibility(8);
                } else {
                    this.ˏ.ॱ.setVisibility(0);
                    this.ˏ.ॱ.setProgress(i);
                }
                if (this.ˏ.ˋ.getVisibility() == 8 && i >= 80 && !this.ˏ.ͺ && this.ˏ.ˋॱ == 1) {
                    this.ˏ.ͺ = true;
                    this.ˏ.ॱˋ();
                }
            }
        }

        public void onReceivedTitle(WebView webView, String str) {
            this.ˏ.ˎ(str);
        }

        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            return true;
        }
    }

    public class e extends WebViewClient {
        final /* synthetic */ ayq ॱ;

        public e(ayq o_ayq) {
            this.ॱ = o_ayq;
        }

        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (str == null || str.trim().length() == 0) {
                Log.w("WebViewDelegate", "url is empty");
            } else {
                try {
                    Intent intent = new Intent(ACTION.HWID_SCHEME_URL, Uri.parse(str));
                    if (!(this.ॱ.ᐝ instanceof Activity)) {
                        intent.setFlags(268435456);
                    }
                    this.ॱ.ᐝ.startActivity(intent);
                } catch (Exception e) {
                    Log.w("WebViewDelegate", "There is no browser");
                }
            }
            return true;
        }

        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            this.ॱ.ͺ = false;
            this.ॱ.ˋ(str);
            super.onPageStarted(webView, str, bitmap);
        }

        public void onPageFinished(WebView webView, String str) {
            this.ॱ.ˋ.getSettings().setBlockNetworkImage(false);
            this.ॱ.ˎ(webView.getTitle());
            this.ॱ.ˋ(str);
        }

        public void onReceivedError(WebView webView, int i, String str, String str2) {
            this.ॱ.ˋॱ = 0;
            this.ॱ.ॱ(i);
        }

        @TargetApi(23)
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            super.onReceivedError(webView, webResourceRequest, webResourceError);
        }

        @TargetApi(23)
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            if (webResourceRequest.getUrl().toString().equals(this.ॱ.ॱˊ)) {
                this.ॱ.ˋॱ = 0;
                this.ॱ.ॱ(-1);
                return;
            }
            super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
        }

        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            sslErrorHandler.cancel();
        }
    }

    protected void ॱ(int i) {
        if (this.ˋ != null) {
            this.ˋ.setVisibility(8);
        }
        if (this.ॱ != null) {
            this.ॱ.setIndeterminate(false);
        }
        if (this.ˎ != null) {
            TextView textView = (TextView) this.ˎ.findViewById(o.axa.b.ˋᐝ);
            if (i == -2) {
                textView.setText(h.ॱˊ);
            } else {
                textView.setText(h.ᐝ);
            }
            this.ˎ.setVisibility(0);
        }
    }

    protected void ˋ(String str) {
        this.ॱˊ = str;
    }

    protected void ˎ(String str) {
        this.ॱˋ.ˋ(str);
    }

    private void ॱˋ() {
        this.ˏॱ.postDelayed(new Runnable(this) {
            final /* synthetic */ ayq ॱ;

            {
                this.ॱ = r1;
            }

            public void run() {
                if (this.ॱ.ͺ && this.ॱ.ˋ.getVisibility() == 8 && this.ॱ.ˋॱ == 1) {
                    this.ॱ.ˋ.setVisibility(0);
                }
            }
        }, 300);
    }

    protected boolean ˋ() {
        Context ʻ = ʻ();
        if (ʻ instanceof Activity) {
            return ((Activity) ʻ).isFinishing();
        }
        return true;
    }

    public void ॱ(Context context) {
        this.ᐝ = context;
        this.ʻॱ = azc.ˎ().ॱ();
    }

    public void ˋ(Context context) {
        ˎ();
        ˊ();
        this.ˎ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ayq ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                if (this.ˋ.ˋॱ != 2 && this.ˋ.ˋ != null && this.ˋ.ˎ != null && this.ˋ.ʻॱ()) {
                    this.ˋ.ˋॱ = 1;
                    this.ˋ.ˏ();
                }
            }
        });
        ॱ();
    }

    protected void ॱ() {
        this.ˎ.findViewById(o.axa.b.ˌ).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ayq ˊ;

            {
                this.ˊ = r1;
            }

            public void onClick(View view) {
                if (azc.ˎ().ॱ() >= 14) {
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.settings.WIRELESS_SETTINGS");
                        intent.putExtra("use_emui_ui", true);
                        this.ˊ.ʻ().startActivity(intent);
                        return;
                    } catch (ActivityNotFoundException e) {
                        Log.e("WebViewDelegate", "can not find ACTION_WIRELESS_SETTINGS");
                    }
                }
                try {
                    this.ˊ.ʻ().startActivity(new Intent("android.settings.SETTINGS"));
                } catch (ActivityNotFoundException e2) {
                    Log.e("WebViewDelegate", "can not find ACTION_SETTINGS");
                }
            }
        });
    }

    protected void ˏ() {
        WebBackForwardList copyBackForwardList = this.ˋ.copyBackForwardList();
        if (copyBackForwardList == null || copyBackForwardList.getSize() == 0) {
            ˏ(this.ˊॱ);
        } else {
            this.ˋ.reload();
        }
        this.ˎ.setVisibility(8);
    }

    protected void ˎ() {
        this.ॱˋ.ˊ();
    }

    public void ˊ() {
        WebSettings settings = this.ˋ.getSettings();
        settings.setCacheMode(2);
        settings.setJavaScriptEnabled(this.ʻ);
        settings.setAllowFileAccess(this.ʼ);
        settings.setDatabaseEnabled(true);
        settings.setAllowContentAccess(false);
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setSavePassword(false);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        ॱॱ();
        if (VERSION.SDK_INT >= 21) {
            settings.setMixedContentMode(1);
        }
        this.ˋ.requestFocus();
        if (VERSION.SDK_INT >= 11) {
            settings.setDisplayZoomControls(false);
        }
        settings.setAllowFileAccessFromFileURLs(false);
        settings.setAllowUniversalAccessFromFileURLs(false);
        this.ˋ.removeJavascriptInterface("accessibility");
        this.ˋ.removeJavascriptInterface("accessibilityTraversal");
        this.ˋ.removeJavascriptInterface("searchBoxJavaBridge_");
        this.ˋ.setWebViewClient(new e(this));
        this.ˋ.setWebChromeClient(new c(this));
    }

    protected void ॱॱ() {
    }

    public void ˏ(String str) {
        this.ˋॱ = 1;
        if (this.ॱ != null) {
            this.ॱ.setIndeterminate(false);
        }
        HwHiAppPrivacyJs hwHiAppPrivacyJs = new HwHiAppPrivacyJs(this.ᐝ);
        if (ॱॱ >= 21 && this.ॱˎ) {
            this.ˋ.addJavascriptInterface(hwHiAppPrivacyJs, com.huawei.appmarket.service.webview.js.HwHiAppPrivacyJs.JS_CHECK_MORE_NAME);
        }
        this.ˋ.addJavascriptInterface(hwHiAppPrivacyJs, com.huawei.appmarket.service.webview.js.HwHiAppPrivacyJs.JS_AGRATTR_NAME);
        this.ˋ.loadUrl(str);
    }

    public void ᐝ() {
        ͺ();
    }

    public void ʽ() {
        ˋॱ();
    }

    public int ʼ() {
        if (this.ʻॱ >= 11) {
            Log.d("WebViewDelegate", "load default_webview_emui5");
            return f.ˊॱ;
        }
        Log.d("WebViewDelegate", "load default_webview");
        return f.ॱˊ;
    }

    public void ˋ(View view) {
        this.ˋ = (WebView) view.findViewById(o.axa.b.ॱ);
        this.ˎ = (LinearLayout) view.findViewById(o.axa.b.ˏˎ);
        this.ॱ = (ProgressBar) view.findViewById(o.axa.b.ˋ);
        azb.ˏ(this.ˋ);
        azb.ˏ(this.ˎ);
        azb.ˏ(this.ॱ);
    }

    public void ˊ(Activity activity) {
    }

    public void ˊ(ActionBar actionBar) {
        this.ˊ = actionBar;
    }

    protected Context ʻ() {
        return this.ᐝ;
    }

    protected void ˋॱ() {
        ॱˊ().finish();
    }

    protected Activity ॱˊ() {
        return (Activity) ʻ();
    }

    public void ˏॱ() {
        try {
            if (this.ॱ != null) {
                this.ॱ.setIndeterminate(false);
            }
            if (this.ᐝॱ) {
                if (this.ˋ != null) {
                    this.ˋ.getClass().getMethod("onResume", new Class[0]).invoke(this.ˋ, (Object[]) null);
                }
                this.ᐝॱ = false;
            }
        } catch (Exception e) {
            Log.w("WebViewDelegate", e.toString());
        }
    }

    public void ˊॱ() {
        try {
            if (this.ˋ != null) {
                this.ˋ.getClass().getMethod("onPause", new Class[0]).invoke(this.ˋ, (Object[]) null);
                this.ᐝॱ = true;
            }
        } catch (Exception e) {
            Log.w("WebViewDelegate", e.toString());
        }
    }

    public void ˋ(Configuration configuration) {
        if (this.ˋ != null) {
            this.ˋ.onResume();
        }
    }

    protected void ͺ() {
        this.ᐝॱ = false;
        if (this.ˋ != null) {
            ॱˎ();
            this.ˋ.clearHistory();
            this.ˋ.destroy();
        }
        this.ᐝ = null;
    }

    private void ॱˎ() {
        try {
            ViewParent parent = this.ˋ.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(this.ˋ);
                this.ˋ.removeAllViews();
            }
        } catch (Exception e) {
            Log.w("WebViewDelegate", "removeWebView error");
        }
    }

    private boolean ʻॱ() {
        ConnectivityManager connectivityManager = (ConnectivityManager) ʻ().getApplicationContext().getSystemService("connectivity");
        if (connectivityManager == null) {
            return false;
        }
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
            return false;
        }
        return true;
    }

    public void ˎ(boolean z) {
        this.ॱˎ = z;
    }
}
